package com.itheima.demo03stream;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Demo03StreamCollect {
    public static void main(String[] args) {
        // 把stream的结果存放到list中
        List<String> list = Stream.of("11", "22", "33").collect(Collectors.toList());
        System.out.println("list = " + list);

        // 把stream的结果存放到set中
        Set<String> set = Stream.of("11", "22", "33", "22").collect(Collectors.toSet());
        System.out.println("set = " + set);

        // 把stream的结果存放到set中
        ArrayList<String> arrayList = Stream.of("11", "22", "33", "22").collect(Collectors.toCollection(ArrayList::new));
        System.out.println("arrayList = " + arrayList);

        // 把stream的结果存放到array中
        String[] strings = Stream.of("113", "2222", "33111").toArray(String[]::new);
        for(String s : strings){
            System.out.println("s = " + s + ", length = " + s.length());
        }
    }
}
